package demo.myactuator;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

import org.springframework.boot.actuate.endpoint.annotation.Endpoint;
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation;
import org.springframework.boot.actuate.endpoint.annotation.WriteOperation;
import org.springframework.stereotype.Component;

import util.StatusUtil;


@Component
@Endpoint(id = "myendpoint")
// 一定要加@Component ，不能用  myEndpoint
public class MyEndPoint {
	
	@ReadOperation
    public Map<String,Object> read(){
		Map<String,Object> status = StatusUtil.getData();
		Map<String,Object> map = new HashMap<>(status);
		map.put("now", LocalDateTime.now().toString());
        return map;
    }
	
	
	@WriteOperation
	public void update(String property, String value)  {
	    System.out.println(property+","+value);
	    // post raw  JSON(application/json)
	    // {"property":"myHealthStatus", "value":"FAIL"}
	    StatusUtil.put(property, value);
	}
	
	
}
	